<?php

use Faker\Factory as Faker;
use App\Models\DistributionStatistics;
use App\Repositories\DistributionStatisticsRepository;

trait MakeDistributionStatisticsTrait
{
    /**
     * Create fake instance of DistributionStatistics and save it in database
     *
     * @param array $distributionStatisticsFields
     * @return DistributionStatistics
     */
    public function makeDistributionStatistics($distributionStatisticsFields = [])
    {
        /** @var DistributionStatisticsRepository $distributionStatisticsRepo */
        $distributionStatisticsRepo = App::make(DistributionStatisticsRepository::class);
        $theme = $this->fakeDistributionStatisticsData($distributionStatisticsFields);
        return $distributionStatisticsRepo->create($theme);
    }

    /**
     * Get fake instance of DistributionStatistics
     *
     * @param array $distributionStatisticsFields
     * @return DistributionStatistics
     */
    public function fakeDistributionStatistics($distributionStatisticsFields = [])
    {
        return new DistributionStatistics($this->fakeDistributionStatisticsData($distributionStatisticsFields));
    }

    /**
     * Get fake data of DistributionStatistics
     *
     * @param array $postFields
     * @return array
     */
    public function fakeDistributionStatisticsData($distributionStatisticsFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'date' => $fake->word,
            'type' => $fake->randomDigitNotNull,
            'user_id' => $fake->randomDigitNotNull,
            'pairing_number' => $fake->randomDigitNotNull,
            'verify_number' => $fake->randomDigitNotNull,
            'shipping_number' => $fake->randomDigitNotNull,
            'json' => $fake->text,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $distributionStatisticsFields);
    }
}
